package com.example.orderform.contorller;

import com.example.orderform.otuercall.GoodsService;
import com.example.orderform.server.DeliverGoodsServer;
import com.example.orderform.vo.Order;
import com.example.orderform.vo.Refund;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api
public class DeliverGoodsContorller {
    @Autowired
    DeliverGoodsServer deliverGoodsServer;

    @Autowired
    GoodsService goodsService;

    @ApiOperation("分页待发货查询接口")
    @RequestMapping("/delivercha")

    public List<Order> receivedcha( @RequestParam("q") int q,
                                    @RequestParam("j") int j,
                                    @RequestParam("userid") int userid){
        List<Order>orderList=deliverGoodsServer.delivercha(q, j,userid);

        if (orderList!=null){
            return orderList;
        }
        return null;
    }


    @ApiOperation("代发货条数查询接口")
    @RequestMapping("/taiochasss")

    public int taiochasss(
                       @RequestParam("userid")int userid){

        System.out.println("查订单---userid="+userid);

        return deliverGoodsServer.delivcha(userid);

    }

    @ApiOperation("待发货订单详情查询接口")
    @RequestMapping("/deliorderxq")
    @ResponseBody
    public Order deliorderxq(@RequestParam("orderid")String orderid) {
        Order order = deliverGoodsServer.deliorderxq(orderid);
        return order;

    }

    @ApiOperation("退款页面查询")
    @RequestMapping("/mhselenumber")

    public List mhselenumber(@RequestParam("ordernumber") String ordernumber)
    {

        return deliverGoodsServer.mhseleordernumber(ordernumber);
    }

    @ApiOperation("退款")
    @RequestMapping("/tuikuang")

    public int tuikuang(@RequestParam("ordernumber") String ordernumber
                        )
    {
        deliverGoodsServer.tuikuang(ordernumber);

        return 1;
    }

    @ApiOperation("退款中订单查询")
    @RequestMapping("/tuikuancha")

    public List<Refund> tuikuancha(@RequestParam("userid") int userid){

        List<Refund>refundList=deliverGoodsServer.tuikuancha(userid);

        return refundList;
    }


    @ApiOperation("待发货倒计时")
    @RequestMapping("/daihuodjs")
    public String daihuodjs(@RequestParam("orderid")int orderid
                            ){
        String daihuodjs=deliverGoodsServer.daihundjs(orderid);
        return daihuodjs;
    }

    @ApiOperation("自动发货改状态")
    @RequestMapping("/daihuogai")
    public int daihuogai(@RequestParam("orderid")int orderid){


            int daihuogai=deliverGoodsServer.daihuogai(orderid);
            return daihuogai;

    }

    @ApiOperation("退款新增")
    @RequestMapping("/addordertow")
    public int addordertow( @RequestParam("userid")int userid ,
                            @RequestParam("ordernumber")String ordernumber,
                            @RequestParam("servicetype")String servicetype,
                            @RequestParam("cargostatus")String cargostatus,
                            @RequestParam("price")String price,
                            @RequestParam("refundreason")String refundreason,
                            @RequestParam("refundinstructions")String refundinstructions,
                            @RequestParam("shoopname")String shoopname,
                            @RequestParam("ordercolor")String ordercolor,
                            @RequestParam("picture")String picture
                            ) {
        int ss=deliverGoodsServer.addordertow(userid,ordernumber,servicetype,cargostatus,price,refundreason,refundinstructions,shoopname,ordercolor,picture);
        System.out.println(ss);
        return ss;

    }



    @ApiOperation("待发货后台查询接口")
    @RequestMapping("/daifahuo")

    public List<Order> daifuhuo( @RequestParam("q") int q,
                                 @RequestParam("j") int j
                                 ){
        List<Order>orderList=deliverGoodsServer.daifahuo(q, j);

        if (orderList!=null){
            return orderList;
        }
        return null;
        }




    @RequestMapping("/backfahuocb")
    public int backfahuocb(@RequestParam("orderid") int orderid)
    {
        Order order= deliverGoodsServer.orderxn(orderid);
        goodsService.upxl(order.getSpid(),order.getComitynumber());
        deliverGoodsServer.backfahuo(orderid);
        return 1;
    }



    //后台退款中
    @RequestMapping("/backtuikuan")

    public List<Refund> backtuikuan(){

        List<Refund>orderList=deliverGoodsServer.selecopy2();
        return orderList;
    }
    //后台退款成功
    @RequestMapping("/selecopys2")

    public List<Refund> selecopys2(){

        List<Refund>orderList=deliverGoodsServer.selecopys2();
        return orderList;
    }

    @RequestMapping("/backupdacopy1")

    public int backcopy1(@RequestParam("orderid") int orderid
    )
    {
        deliverGoodsServer.backcopy1(orderid);
        return 1;
    }


    @RequestMapping("/backupdacopy2")

    public int backcopy2(@RequestParam("id") int id
    )
    {
        deliverGoodsServer.backcopy2(id);
        return 1;
    }

    @RequestMapping("/backupdacopy3")

    public int backcopy3(@RequestParam("orderid") int orderid
    )
    {
        deliverGoodsServer.backcopy3(orderid);
        return 1;
    }

    @RequestMapping("/fahuochengg")

    public List<Order> fahuochengg(@RequestParam("userid")int userid){

        List<Order>orderList=deliverGoodsServer.selefahuo(userid);
        return orderList;
    }
}
